package cn.dengta.webapp.trade.entity;

import cn.dengta.common.model.Status;
import cn.dengta.webapp.base.entity.BaseEntity;
import cn.dengta.webapp.user.model.MetaType;
import cn.dengta.webapp.user.model.MetaType.TypeValue;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import me.codeplayer.util.StringUtil;
import me.codeplayer.util.X;

/**
 * 元数据表
 *
 * @author lgy
 * @since 2022-08-17
 */
@Setter
@Getter
@Accessors(chain = true)
@TableName("dt_meta")
public class Meta extends BaseEntity {

	/** 所属类型 */
	private MetaType type;
	/** 值 */
	private String value;
	/** 名称 */
	private String label;
	/** 备注 */
	private String remark;
	/** 排序 */
	private Integer sort;
	/** 状态：0=停用，1=启用 */
	private Integer status;

	private transient TypeValue typeValue;

	public Meta init(Meta input) {
		this.type = X.expectNotNull(type, input.type);
		this.value = X.expectNotNull(input.value, value);
		this.label = X.expectNotNull(label, input.label);
		this.remark = X.expectNotNull(input.remark, remark);
		this.sort = X.expectNotNull(input.sort, sort, 0);
		this.status = X.expectNotNull(input.status, status, Status.YES.value);
		return this;
	}

	public <T extends TypeValue> TypeValue findTypeValueConfig() {
		if (typeValue == null) {
			if (StringUtil.notEmpty(this.value) && type.typeValueClass != null) {
				return typeValue = JSONObject.parseObject(this.value, type.typeValueClass);
			}
		}
		return typeValue;
	}

	public static final String TYPE = "type";
	public static final String VALUE = "value";
	public static final String LABEL = "label";
	public static final String REMARK = "remark";
	public static final String SORT = "sort";
	public static final String STATUS = "status";

	/** 数据库key {@link MetaType} */
	// registerLimit注册限制
	/** 单设备注册数量 */
	public static final String registerLimitCount = "registerLimitCount";
	/** 注册超过次数后开始延长 */
	public static final String registerLimitTimes = "registerLimitTimes";
	/** 延长时间（天） */
	public static final String registerExtendDay = "registerExtendDay";
	// lottery抽奖转盘
	/** 抽奖价格 */
	public static final String lotteryPrize = "lotteryPrize";
	/** 每日免费抽奖次数 */
	public static final String perLotteryFreeTimes = "perLotteryFreeTimes";
	// systemConfig系统配置
	/** 钻石标记 */
	public static final String femaleMarkCoinOpen = "femaleMarkCoinOpen";
	/** vip陪聊标记 */
	public static final String femaleMarkVipOpen = "femaleMarkVipOpen";

	// femaleConfig女主播配置
	/** 男用户对当前视频的女用户超过规定亲密度，放行拦截 */
	public static final String riskPermitIntimacy = "riskPermitIntimacy";
	/** 男用户超过累计登陆天数，放行拦截 */
	public static final String riskPermitLoginTimes = "riskPermitLoginTimes";
	/** 男用户超过连续登陆天数，放行拦截 */
	public static final String riskPermitContinuousLogin = "riskPermitContinuousLogin";
	/** 老虎机初始化数据，只用于测试、开发方便快速测试、不能用于生产环境 */
	public static final String tigerSlot = "tigerSlot";
	// live直播配置
	/** 在线人数系数 */
	public static final String onlineUserLiveFactor = "onlineUserLiveFactor";
	/** 送钻石数系数 */
	public static final String sendCoinLiveFactor = "sendCoinLiveFactor";
	/** 聊天句数系数 */
	public static final String msgLiveFactor = "msgLiveFactor";
	/** 点赞系数 */
	public static final String digLiveFactor = "digLiveFactor";
	/** 1V1聊天礼物引导 */
	public static final String SINGLE_GIFT_GUIDE = "single_gift_guide";
	/** 直播礼物引导 */
	public static final String LIVE_GIFT_GUIDE = "live_gift_guide";
	// chatEval聊天评价配置
	/** 视频评价最低时长 */
	public static final String videoEvalLimit = "videoEvalLimit";
	// disturb 男用户防骚扰
	/** 防骚扰开关 */
	public static final String disturbOpen = "disturbOpen";
	/** 防骚扰间隔 */
	public static final String disturbInterval = "disturbInterval";
	/** 接听方式 */
	public static final String disturbStyle = "disturbStyle";
	/** 亲密度值 男用户解锁图片 */
	public static final String unlockImage = "unlockImage";
	/** 亲密度值 男用户解锁通话 */
	public static final String unlockCall = "unlockCall";
	/** 亲密度值 女用户解锁通话 */
	public static final String femaleUnlockCall = "femaleUnlockCall";

}
